package com.example.annasbook.repository.convert;

import cn.hutool.core.date.DateUtil;
import com.example.annasbook.model.BookModel;
import com.example.annasbook.model.BookModelVo;
import com.example.annasbook.repository.entity.BookEntity;
import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
import org.mapstruct.MappingTarget;

@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface BookConvert {
    default Long map(String date) {
        if (date == null) return null;
        return DateUtil.parse(date, "yyyy-MM-dd HH:mm:ss.SSS").getTime();
    }

    void fillBookEntity(@MappingTarget BookEntity b, BookModel bookModel);

    BookModel toBookModel(BookModel item);

    BookEntity toBookEntity(BookModel x);

    BookModelVo BookModelVo(BookEntity bookEntity);
}
